// resourcemanager.h : contains the singleton class for resource management that is required throughout the application
//$Id: ResourceManager.h 48 2009-09-28 22:27:40Z brwarner2 $
#pragma once

//Forward of game engine
class CSymbianEngine;

//Resource Manager class
class CResourceManager
{
public:
	//Constructor
	CResourceManager(void);

	//Destructor
	~CResourceManager(void);

	//Release function
	void Release( void );

public:
	//Creates a new skin with the given texture
	bug::render::SkinPointer CreateTexture( const std::string& filename );

	//Releases a skin
	void ReleaseSkin( bug::render::SkinPointer );

	//Opens a filestream
	std::fstream File( const std::string& filename, std::ios_base::openmode );

	//Allow private access
	friend class CSymbianEngine;

public:
	//Retrieves the render sprite
	bug::render::CSprite* GetSprite(void) { return m_pSprite; }

	//Gets the texture manager :O
	bug::render::ITextureManager* GetTextureManager(void) { return m_pRenderDevice->GetTextureManager(); }

	//Gets the render device
	bug::render::IRenderDevice* GetRender(void) { return m_pRenderDevice; }

	//Gets the input device
	bug::input::IInputDevice* GetInput(void) { return m_pInputDevice; }

	//Gets the game engine
	CSymbianEngine* GetEngine(void) { return m_pEngine; }

private:
	//Texture struct
	struct Texture
	{
		bug::render::SkinPointer skin; //Skin
		bug::render::TexturePointer tex; //Texture
		unsigned int usage; //Usage count
	};

	//Map types
	typedef std::map< std::string, Texture > TextureList;
	typedef std::map< bug::render::SkinPointer, std::string > TextureNameList;

	//List of active textures by name
	TextureList m_skins;

	//List of skin pointers to their names
	TextureNameList m_skinname;

	//Releases a texture object
	void ReleaseTextureObject( const Texture& );

private:
	//Render device
	bug::render::IRenderDevice* m_pRenderDevice;

	//Input device
	bug::input::IInputDevice* m_pInputDevice;

	//Audio device
	bug::audio::IAudioDevice* m_pAudioDevice;

	//Sprite
	bug::render::CSprite* m_pSprite;

	//Symbian game
	CSymbianEngine* m_pEngine;
};

//Retrieves a copy of the resource manager
CResourceManager* Resource(void);
void Resource( CResourceManager* );